﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;

namespace gpuimp.core.Configuration
{
    class ConfigManager
    {
        /**
         * ReadConfigFile takes in a XML file.
         * The file can contain data for either making a new tool, configuring a current tool, or creating a macro.
         * ReadConfigFile will then parse out the appropriate data
         * */
        public void ReadConfigFile(string configFileName)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(configFileName);

                #region flags
                //flags to know what type of xml node is being read
                bool readingTool = false;
                bool readingToolConfig = false;
                bool readingMacro = false;
                #endregion

                foreach (XmlNode node in doc.DocumentElement.ChildNodes)
                {
                    readingTool = (node.Name == "Tool");
                    readingToolConfig = (node.Name == "ConfigTool");
                    readingMacro = (node.Name == "Macro");

                    if (readingTool)
                    {
                    }

                    if (readingToolConfig)
                    {
                        getToolConfigAttributes(node);
                    }
                 
                    if (readingMacro)
                    {
                    }
                }
            }
            #region catches
            //catches to make sure the file is there
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e);
            }
            catch (FileLoadException e)
            {
                Console.WriteLine(e);
            }
            #endregion 
        }

        private void getToolAttributes()
        {

        }

        private void getToolConfigAttributes(XmlNode node)
        {
            #region getToolConfigAttributes
            XmlAttribute name = node.Attributes["Name"];
            XmlAttribute minSize = node.Attributes["minSize"];
            XmlAttribute maxSize = node.Attributes["maxSize"];
            XmlAttribute minOpacity = node.Attributes["minOpacity"];
            XmlAttribute maxOpacity = node.Attributes["maxOpacity"];
            XmlAttribute minScatter = node.Attributes["minScatter"];
            XmlAttribute maxScatter = node.Attributes["maxScatter"];
            XmlAttribute minColorVar = node.Attributes["minColorVar"];
            XmlAttribute maxColorVar = node.Attributes["maxColorVar"];
            String typeToSet = node.Value;
            node.Attributes.Remove(name);
            node.Attributes.Remove(minSize);
            node.Attributes.Remove(maxSize);
            node.Attributes.Remove(minOpacity);
            node.Attributes.Remove(maxOpacity);
            node.Attributes.Remove(minScatter);
            node.Attributes.Remove(maxScatter);
            node.Attributes.Remove(minColorVar);
            node.Attributes.Remove(maxColorVar);
            #endregion
        }

        private void getMacro()
        {

        }
    }
}
